import api from '@/api'
import { basePermissions } from '@/settings'

export async function getUserInfo() {
  const res = await api.getUser()
  // const { id, username, profile, roles, currentRole,name,headPortrait } = res.data || {}
  const { id, username, name, lastProjectId } = res.data || {}
  // return {
  //   id,
  //   username,
  //   avatar: profile?.avatar,
  //   nickName: profile?.nickName,
  //   gender: profile?.gender,
  //   address: profile?.address,
  //   email: profile?.email,
  //   roles,
  //   currentRole,
  // }
  return {
    id,
    username,
    name,
    lastProjectId,
    // nickName:username,
    // avatar: headPortrait,
    avatar: 'https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif?imageView2/1/w/80/h/80',
  }
}

export async function getPermissions() {
  let asyncPermissions = []
  try {
    const res = await api.getRolePermissions()
    asyncPermissions = res?.data || []
  }
  catch (error) {
    console.error(error)
  }
  return basePermissions.concat(asyncPermissions)
}
